package com.atguigu.springcloud.controller;  
  
import com.atguigu.springcloud.service.PaymentHystrixService;
//import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
//import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;  
import org.springframework.web.bind.annotation.PathVariable;  
import org.springframework.web.bind.annotation.RestController;  
import javax.annotation.Resource;  
  
@RestController  
@Slf4j  
public class OrderHystrixController {  
    @Resource  
    private PaymentHystrixService paymentHystrixService;  
  
    @GetMapping("/consumer/payment/hystrix/ok/{id}")  
    public String paymentInfo_OK(@PathVariable("id") Integer id){  
        String result = paymentHystrixService.paymentInfo_OK(id);  
        log.info("*******result:"+result);  
        return result;  
    }  

    @GetMapping("/consumer/payment/hystrix/timeout/{id}")
//    @HystrixCommand(
//        // fallbackMethod = "paymentInfo_TimeOut_FallBack",
//        defaultFallback = "commonFallBack",
//        commandProperties = {
//                @HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds", value = "2000")
//        }
//    )
    public String paymentInfo_TimeOut(@PathVariable("id") Integer id){
        String result = paymentHystrixService.payment_Timeout(id);  
        log.info("*******result:"+result);  
        return result;
    }

    public String paymentInfo_TimeOut_FallBack(Integer id) {

        return "Consumer 端采用降级方案！";
    }

    // 备选方案方法，由于要适配各个方法，各个业务方法参数列表未必一致，所以框架要求是一个无参的方法。
    public String commonFallBack() {
        return "类中统一使用的备选方案，降级方法。";
    }
  
}